# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=pcre-heavy
pkgname=haskell-pcre-heavy
pkgver=1.0.0.3
pkgrel=15
pkgdesc="A regexp (regex) library on top of pcre-light you can actually use"
url="https://codeberg.org/valpackett/pcre-heavy"
license=("custom:PublicDomain")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base-compat' 'haskell-pcre-light' 'haskell-string-conversions')
makedepends=('ghc' 'uusi' 'haskell-glob' 'haskell-doctest')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('5fc2f1b6e634e501927551edccbaf3fa2b3f76e4c1d491f0912d8371e5a13cd964317383d5cd274d3b64ca5976f5e2783968caadb67f3a9da3910398cd80f5a6')

prepare() {
    cd $_hkgname-$pkgver
    uusi -d semigroups $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 "UNLICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/UNLICENSE"
    rm -f "${pkgdir}/usr/share/doc/${pkgname}/UNLICENSE"
}
